#ifndef CSIMPLEWINDOW_H_INCLUDED
#define CSIMPLEWINDOW_H_INCLUDED

/**
 *
 * \file CSimpleWindow.h
 * \brief This file contains the CSimpleWindow class declaration.
 * \author Vladimir Klubkov (aka marked)
 *
 * Last changes date:
 * \date 13.03.2011
 *
 * Copyright 2011 Vladimir Klubkov <marked-one@yandex.ru>
 *
 * This file is part of OOXlib.
 *
 * OOXLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * OOXlib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OOXlib; if not, you can try to find  it here:
 * http://www.gnu.org/licenses/gpl.txt
 * or write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "CColor.h"
#include "CIcon.h"
#include "shapes.h"
#include "CDefaultEventHandler.h"

namespace OOXlib {

/**
 * \class CSimpleWindow
 * Simple window class.
 */
class CSimpleWindow : public IWindow {
public:
    /**
     * \class CNULLPtrIWindowException
     * Exception handler class.
     */
    class CNULLPtrIWindowException : public CException {
    public:
        CNULLPtrIWindowException(const ::std::string &File, const int iLine, const ::std::string &Function);
    };
    /**
     * \class CXStringListToTextPropertyException
     * Exception handler class.
     */
    class CXStringListToTextPropertyException : public CException {
    public:
        CXStringListToTextPropertyException(const ::std::string &File, const int iLine, const ::std::string &Function);
    };
public:
    CSimpleWindow(const CXServerConnection *pXServerConnection, const CScreen *pScreen);
    CSimpleWindow(const CXServerConnection *pXServerConnection, const CScreen *pScreen, const CUInt2dRectangle &Rectangle, const unsigned int iEventMask,
                  const IEventHandler *pEventHandler, const ::std::string &WindowName);
    CSimpleWindow(const CXServerConnection *pXServerConnection, const CScreen *pScreen, IWindow *pParentWindow, const CUInt2dRectangle &Rectangle,
                  const unsigned int iEventMask, const IEventHandler *pEventHandler, const ::std::string &WindowName, const ::std::string &IconPath,
                  const CColor *pBackgroundColor, const unsigned int iBorderWidth, const bool bIsResizeable);
    CSimpleWindow(const CXServerConnection *pXServerConnection, const CScreen *pScreen, IWindow *pParentWindow, const CUInt2dRectangle &Rectangle,
                  const unsigned int iEventMask, const IEventHandler *pEventHandler, const ::std::string &WindowName, const ::std::string &ClassName,
                  const ::std::string &IconPath, const CColor *pBackgroundColor, const unsigned int iBorderWidth, const bool bIsResizeable, const bool bShowCursor);
    ~CSimpleWindow();
// Getters.
    ::Window Get() const;
    operator ::Window() const;
    CUInt2dRectangle GetRectangle() const;
    CUInt2dPoint GetPosition() const;
    CUInt2dSize GetSize() const;
// Setters.
    void SetRectangle(const CUInt2dRectangle &Rectangle);
// Register window.
    size_t Register(IWindow *pWindow);
    void Unregister(const size_t iId);
// Run event handler
    bool RunEventHandler(::XEvent &Event);
// Hide/show window.
    void Hide();
    void Show();
// Handlers.
    void OnCreate();
    void OnDestroy();
    void OnHide();
    void OnShow();
    void OnExpose();
    void OnGotFocus();
    void OnLostFocus();
    void OnKeyPress(const ::XID iKey UNUSED_PARAM);
    void OnKeyRelease(const ::XID iKey UNUSED_PARAM);
    void OnButtonPress(const unsigned int iButton UNUSED_PARAM, const int iX UNUSED_PARAM, const int iY UNUSED_PARAM);
    void OnButtonRelease(const unsigned int iButton UNUSED_PARAM, const int iX UNUSED_PARAM, const int iY UNUSED_PARAM);
    void OnMouseEnter(const int iX UNUSED_PARAM, const int iY UNUSED_PARAM);
    void OnMouseExit(const int iX UNUSED_PARAM, const int iY UNUSED_PARAM);
    void OnMouseMove(const int iX UNUSED_PARAM, const int iY UNUSED_PARAM);
private:
    CSimpleWindow(const CSimpleWindow &Other);
    CSimpleWindow& operator=(const CSimpleWindow &Other);
protected:
    void Create(const CScreen *pScreen,IWindow *pParentWindow, const CUInt2dRectangle &Rectangle, const unsigned int iEventMask, const IEventHandler *pEventHandler,
                const ::std::string &WindowName, const ::std::string &ClassName, const ::std::string &IconPath, const CColor *pBackgroundColor, const unsigned int iBorderWidth,
                const bool bIsResizeable, const bool bShowCursor);
    void Destroy();
    bool HandleEvents();
protected:
    const CXServerConnection *m_pXServerConnection;
    const CScreen *m_pScreen;
    const IEventHandler *m_pEventHandler;
    CIcon *m_pIcon;
    bool m_bHasParent;
    bool m_bShowCursor;
    unsigned int m_iEventMask;
    CUInt2dRectangle m_Rectangle;
    ::Window m_Window;
    IWindow *m_pParentWindow;
    ::std::vector<IWindow*> m_Windows;
    size_t m_iId;
    ::std::vector<size_t> m_FreeIds;
};

} // OOXlib

#endif // CSIMPLEWINDOW_H_INCLUDED
